﻿using System.Data;
using SqlSugar;

namespace StoreAPI.Services
{
    public interface IBaseService<T> where T : class, new()
    {
        
        /// <summary>
        /// 获取最大的主键
        /// </summary>
        /// <returns></returns>
        int GetMaxId();
        /// <summary>
        /// 判断一个模型是否存在
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        bool Exists(int model);
        /// <summary>
        /// 添加一个模型
        /// </summary>
        /// <param name="model">模型</param>
        /// <returns>是否成功，true成功，false失败</returns>
        bool Add(T model);

        /// <summary>
        /// 修改一个模型
        /// </summary>
        /// <param name="model">模型</param>
        /// <returns>是否成功，true成功，false失败</returns>
        bool Update(T model);

        /// <summary>
        /// 根据一个主键删除一个模型
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns>是否成功，true成功，false失败</returns>
        bool Delete(int primaryKey);
        /// <summary>
        /// 批量删除数据
        /// </summary>
        /// <returns></returns>
        bool DeleteList(int[] primaryKeys);

        /// <summary>
        /// 根据一个主键获取一个模型
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns>模型</returns>
        T GetModel(int primaryKey);
        /// <summary>
        /// 根据一行数据获取一个模型
        /// </summary>
        /// <param name="row">行</param>
        /// <returns></returns>
        T DataRowToModel(DataRow row);

        /// <summary>
        /// 获取所有模型
        /// </summary>
        /// <param name="exp">查询表达式</param>
        /// <returns>列表</returns>
        List<T> GetListAll(Expressionable<T> exp);
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        /// <returns></returns>
        List<T> GetList(Expressionable<T> exp, int Top);
        /// <summary>
        /// 获取记录数
        /// </summary>
        /// <returns></returns>
        int GetRecordCount(Expressionable<T> exp);
        /// <summary>
        /// 获取分页模型
        /// </summary>
        /// <param name="exp">查询表达式</param>
        /// <param name="totalPage">总页数</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">条数</param>
        /// <returns>列表</returns>
        List<T> GetListByPage(Expressionable<T> exp, out int totalPage, int pageIndex = 1, int pageSize = 10);
    }
}
